import React from 'react';

import './style/';
import {WeaDialog, WeaFormItem, WeaSearchGroup, WeaRichText, WeaTools, WeaLocaleProvider} from "ecCom";
import {Icon, Button, message} from 'antd'
const getLabel = WeaLocaleProvider.getLabel;
class Copyright extends React.Component {

    state = {
        copyrightcon:"",
        visible:false
    }


    getDatas = () => {
        WeaTools.callApi('/api/portal/customcopyright/getCopyright','GET',{
            "id":this.props.id
        }).then((result) => {
            if(result.api_status==true&&result.isCz==true){
                this.setState({copyrightcon:result.setting.copyrightcon});
            }else if(result.api_status==true&&result.isCz==false){
            }
        })
    }

    saveSetting= () =>{
        WeaTools.callApi('/api/portal/customcopyright/saveCopyright','POST',{
            jsonStr: JSON.stringify({
                "copyrightcon":this.state.copyrightcon,
                "id":this.props.id,
            })
        }).then((result) =>{
            if(result.api_status==true){
                this.setState({visible:false});
                message.success(getLabel(83551,"保存成功！"),2);
            }else {
                message.error(getLabel(84544,"保存失败！"),2);
            }
        })
        this.setState({visible: false});
    }


    openDia = () => {
        this.setState({visible: true});
    }
    componentDidMount(){
        this.getDatas();
    }

    onCancel = () => {
        this.getDatas();
        this.setState({visible:false})
    }


    render() {
        const {id,isSetting} = this.props
        const {copyrightcon,visible} = this.state;
        return (
            <div className={`copyright copyright-${id}`} onMouseEnter={()=>{$(`.setting-button-${id}`).show()}} onMouseLeave={()=>{$(`.setting-button-${id}`).hide()}}>

                <p dangerouslySetInnerHTML={{ __html: copyrightcon }} />

                {
                    isSetting == true ? (
                        <div className={`setting-button setting-button-${id}`}>
                            <span  onClick={this.openDia} className="icon-coms-Flow-setting" />
                        </div>
                    ) : null
                }
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@byoqs7`} visible={visible} onCancel={this.onCancel} title={getLabel(387745,"文本设置")}  style={{width:'900px',height : 600}}>
                    <div className={`setting setting-${id}`}>
                        <WeaRichText ecId={`${this && this.props && this.props.ecId || ''}_WeaRichText@axd2d2`} ref='test'
                                     value={copyrightcon}
                                     ckConfig={{
                                         toolbar:[
                                             { name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates'] },
                                             { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
                                             { name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt'] },
                                             { name: 'forms', items: ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'] },
                                             '/',
                                             { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] },
                                             { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language'] },
                                             { name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
                                             { name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe'] },
                                             '/',
                                             { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
                                             { name: 'colors', items: ['TextColor', 'BGColor'] },
                                             { name: 'tools', items: ['Maximize', 'ShowBlocks'] },
                                         ],
                                         height: 430
                                     }}
                                     onChange={vlaue =>{ this.setState({copyrightcon: vlaue})}}
                        />
                        <div style={{position:"absolute",bottom:7,"margin-left": "67%"}}>
                            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@kyl9a2`} onClick={this.saveSetting} type="primary">{getLabel(33703,"确认")}</Button>
                            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@139zgo`} onClick={this.onCancel} style={{"margin-left":10}}>{getLabel(31129,"取消")}</Button>
                        </div>
                    </div>
                </WeaDialog>

            </div>
        );
    }
}

export default Copyright;